/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import dal.QueryExecuter;
import entities.Manager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Vector;

/**
 *
 * @author MinhDuc
 */
public class ManagerBO {

    private QueryExecuter query = new QueryExecuter();

    public ManagerBO() {
    }

    public boolean addManager(Manager manager) {
        String insert = "insert into Manager(FullName,UserName,Password)\n"
                + "values ('" + manager.getFullName() + "','" + manager.getUserName() + "','" + manager.getPassword() + "')";
        int rt = query.updateQuerry(insert);
        return rt > 0 ? true : false;
    }

    public boolean checkLogin(Manager manager) {
        boolean value = false;
        String getManager = "select * from Manager\n"
                + "where UserName = '" + manager.getUserName() + "' and Password = '" + manager.getPassword() + "'";
        ResultSet rs = query.exeQuerry(getManager);
        try {
            if (rs.next() == true) {
                value = true;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return value;
    }

    public Vector<Manager> showAll() {
        Vector<Manager> data = new Vector<Manager>();
        String sql = "SELECT * FROM Manager";
        ResultSet rs = query.exeQuerry(sql);
        try {
            while (rs.next()) {
                Manager manager = new Manager();
                manager.setManagerID(rs.getInt(1));
                manager.setFullName(rs.getNString(2));
                manager.setUserName(rs.getNString(3));
                manager.setPassword(rs.getNString(4));

                data.add(manager);
            }
            rs.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return data;
    }
}
